package com.kitty.game.rank.service;

import com.kitty.common.cache.RedisService;
import com.kitty.game.activity.service.boos.handler.DaRiJinWuHandlr;
import com.kitty.game.enter.RespGeneralNotify;
import com.kitty.game.rank.message.*;

import com.kitty.game.role.model.Role;
import com.kitty.game.utils.NotifyModules;
import com.kitty.mina.cache.DataCache;
import com.kitty.mina.cache.SessionUtils;
import com.kitty.mina.message.MessagePusher;
import org.apache.mina.core.session.IoSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

import static java.lang.Thread.sleep;

@Service
public class RankDaRiService {
    int i = 1;
    @Autowired
    RedisService redisService;
    public void viewBossRank(IoSession session, ReqWorldBossRank reqWorldBossRank) {
        Role role = SessionUtils.getRoleBySession(session);
        RespGeneralNotify respGeneralNotify = new RespGeneralNotify();
        respGeneralNotify.setNotify((short) NotifyModules.NOTIFY_OPEN_DLG); //打开对话框
        respGeneralNotify.setValue("WorldBossRankDlg");
        MessagePusher.pushMessage(role, respGeneralNotify);
//        WorldBossRank worldBossRankList  = new WorldBossRank();
//        Random random = new Random();
//        int successRate = random.nextInt(10000) + 1;
//        worldBossRankList.setName("A"+ successRate);
//        worldBossRankList.setRank((short) i);
//        worldBossRankList.setDamage(successRate+5);
//        redisService.add("dariRank",worldBossRankList);

        RespWorldBossRank respWorldBossRank = new RespWorldBossRank();
        List<WorldBossRank> dariRank = redisService.getRankListType("dariRank");
        WorldBossRank worldBossRank  = new WorldBossRank();
        worldBossRank.setName(role.getName());
        int rank = redisService.find("dariRank", role.getName());
        worldBossRank.setRank((short)rank );
        int dariScore = redisService.findScore("dariRank", role.getName());
        worldBossRank.setDamage(dariScore);
        dariRank.add(worldBossRank);
        respWorldBossRank.setWorldBossRankList(dariRank);
        MessagePusher.pushMessage(role, respWorldBossRank);


    }

    public void viewBossLife(IoSession session, ReqWorldBossLife reqWorldBossRank) {
        Role role = SessionUtils.getRoleBySession(session);
        RespWorldBossLife respWorldBossRank = new RespWorldBossLife();
        int worldBossLife = Integer.parseInt(DataCache.REDIS_DATA.get("dari_life").toString());
        respWorldBossRank.setMaxLife(worldBossLife+"");
        respWorldBossRank.setCurrentLife(DaRiJinWuHandlr.dari_life+"");
        MessagePusher.pushMessage(role, respWorldBossRank);
    }

    public static void main(String[] args) {
        long time = System.currentTimeMillis();
        System.out.println(time);
        BigDecimal subtract = new BigDecimal("1.0").subtract(new BigDecimal(time * Math.pow(10, Math.negateExact(String.valueOf(time).length()))));
//
//        System.out.println(subtract);
//        try {
//            sleep(1);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        long time2 = System.currentTimeMillis();
//        BigDecimal subtract2 = new BigDecimal("1.0").subtract(new BigDecimal(time2 / Math.pow(10,(int)Math.log10(time)+1 )));
//        System.out.println(subtract2);
//
//
//        double a= 1-time/Math.pow(10,(int)Math.log10(time)+1);
//        System.out.println(a);
//
//        double b= 1-time2/Math.pow(10,(int)Math.log10(time2)+1);
//        System.out.println(b);
    }
}
